package com.zlh123.controller;

import com.zlh123.commom.util.PageResult;
import com.zlh123.commom.util.R;
import com.zlh123.entity.BorrowRecord;
import com.zlh123.service.IBorrowRecordService;
import com.zlh123.vo.RecordVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author zlh
 * @since 2025-01-13
 */
@RestController
@RequestMapping("/record")
public class BorrowRecordController {
    @Autowired
    private IBorrowRecordService borrowRecordService;
    //借阅记录列表
    @RequestMapping("/list")
    public R getBRList() {
        return R.ok().data("list",borrowRecordService.list());
    }
    //分页
    @GetMapping("/findRecordsByPage/{page}/{pageSize}")
    public R findRecordsByPage(@PathVariable("page") int page,
                        @PathVariable("pageSize") int pageSize) {
        PageResult<BorrowRecord> student=borrowRecordService.findRecordsByPage(page,pageSize);
        return R.ok().data("list",student);
    }
    //条件查询并分页
    @PostMapping("/search/{page}/{pageSize}")
    public R search(@PathVariable("page") int page,
                    @PathVariable("pageSize") int pageSize,
                    @RequestBody(required = false) RecordVo recordVo) {
        PageResult<BorrowRecord> data=borrowRecordService.search(page,pageSize,recordVo);
        return R.ok().data("list",data);
    }
//    //添加学生
//    @PostMapping("/add")
//    public R add(@RequestBody Student student) {
//        boolean flag= studentService.add(student);
//        return flag ? R.ok().message("添加学生成功") : R.error().message("添加学生失败");
//    }
//    //修改学生
//    @PutMapping("/update")
//    public R update(@RequestBody Student student) {
//        boolean flag = studentService.updateById(student);
//        return flag ? R.ok().message("修改学生成功") : R.error().message("修改学生失败");
//    }
//    @DeleteMapping("/delete/{ids}")
//    public R delete(@PathVariable("ids") String ids) {
//        String[] split = ids.split(",");
//        List<String> sids = Arrays.asList(split);
//        return studentService.removeByIds(sids) ? R.ok().message("删除学生成功!") : R.error().message("删除学生失败!");
//    }
}
